<?php

declare(strict_types=1);

namespace App\CustHub\Service;

use App\Common\Service\CommonRoleService;
use Hyperf\Di\Annotation\Inject;
use Mine\Exception\NormalStatusException;
use Override;

class RoleService extends CommonRoleService
{

    #[Inject]
    protected ChMenuService $menuService;

    #[Override]
    public function save(array $data): mixed
    {
//        if ($this->mapper->checkRoleCode($data['code'])) {
//            throw new NormalStatusException(t('system.rolecode_exists'));
//        }

        $data['code'] = make_coupon_card();
        $data['menu_ids'] = $this->menuService->getMenuIds($data['main_uid']);
        return $this->mapper->save($data);
    }
}